home *** CD-ROM | disk | FTP | other *** search
/ Creative Review 28 / Creative-Review-CD-ROM-28.iso / pc / kungfu / assets / game.dir / 00036_Script_player class < prev    next >
Text File  |  1997-08-08  |  12KB  |  514 lines

  1. -- player class method
  2. -- --------------------------------------------------
  3.  
  4. property ancestor
  5.  
  6. property repeatflag
  7.  
  8. property priorityindex
  9. property repeatindex
  10.  
  11. property bounceindex
  12.  
  13. property score
  14.  
  15. property lives
  16. property fullhealth
  17.  
  18. property victory
  19. property walkon
  20.  
  21. -- --------------------------------------------------
  22. global gkey
  23. global gjoystick
  24. global gsound
  25. global gcell
  26. global gscore
  27. global ghealth
  28. global gstar
  29. global glife
  30. global ggame
  31. global gboss
  32.  
  33. -- ==================================================
  34. -- new method
  35. -- --------------------------------------------------
  36. on new me
  37.   
  38.   minit me
  39.   return me
  40.   
  41. end mnew 
  42.  
  43. -- ==================================================
  44. -- minit method
  45. -- --------------------------------------------------
  46. on minit me
  47.   
  48.   --  put "in minit player"
  49.   
  50.   set fullhealth = 290
  51.   set score = 0
  52.   
  53.   set priorityindex =  data2list ( "move priority data" )
  54.   set repeatindex = data2list ( "move repeat data" )
  55.   set bounceindex = data2list ( "bounce data" )
  56.   
  57.   set props = [:]
  58.   
  59.   setaprop props, #health, fullhealth
  60.   setaprop props, #type, #player 
  61.   setaprop props, #data, #player
  62.   
  63.   set animdata = data2list ( "player anim data" )
  64.   
  65.   setaprop props, #animdata , animdata
  66.   
  67.   setaprop props, #drawdata , [ #channel : 18 ]
  68.   
  69.   set ancestor = new ( script "actor class" , props )
  70.   
  71.   set lives = 4
  72.   
  73.   set victory = new ( script "victory class" , ancestor )
  74.   set walkon = new ( script "walkon class" , ancestor )
  75.   
  76.   --  put "out minit player"
  77.   
  78. end minit
  79.  
  80. -- ==================================================
  81. -- mdispose me
  82. -- --------------------------------------------------
  83. on mdispose me
  84.   
  85.   --  put "in mdispose player class"
  86.   
  87.   mdispose ancestor
  88.   
  89.   set ancestor = 0
  90.   set priorityindex = 0
  91.   set repeatindex = 0
  92.   
  93.   --  put "in mdispose player class"
  94.   
  95. end mdispose me
  96.  
  97.  
  98. -- ==================================================
  99. -- mkeydown method
  100. -- --------------------------------------------------
  101. on mkeydown me , thekey
  102.   
  103.   --  put "* in mkeydown player: " thekey
  104.   
  105.   set  the nextmove of me  = mkeytomove ( me, thekey )
  106.   set  the nextmoveflag  of me  = true
  107.   
  108.   --    put "(the nextmoveflag  of me): " , (the nextmoveflag  of me)
  109.   --    put "(the nextmove of me): " , (the nextmove of me)
  110.   
  111.   --  put "* out mkeydown player: "
  112.   
  113. end mkeydown 
  114.  
  115. -- ==================================================
  116. -- mjoystick method
  117. -- -------------------------------------------------
  118. on mjoystick me, newdirection
  119.   
  120.   -- put "in mjoystick player: " 
  121.   
  122.   set joyflag = false
  123.   
  124.   if repeatflag or (the nextmoveflag  of me) then
  125.     if not ( newdirection = the direction of me ) then  set joyflag = true
  126.     
  127.   else set joyflag = true
  128.   
  129.   if joyflag then 
  130.     set the nextmove of me = mkeytomove ( me, newdirection )
  131.     set the nextmoveflag  of me = true
  132.   end if
  133.   
  134.   -- put "out mjoystick player: " 
  135.   
  136. end mjoystick
  137.  
  138. -- ==================================================
  139. -- manimfinish method
  140. -- --------------------------------------------------
  141. on manimfinish me
  142.   
  143.   --  put "in manimfinish: " 
  144.   --  put "(the nextmoveflag  of me): " , (the nextmoveflag  of me)
  145.   --  put "(the nextmove of me): " , (the nextmove of me)
  146.   
  147.   mmovefinish ( me )
  148.   
  149.   if mcheckstun ( me ) then return
  150.   
  151.   if (the nextmoveflag  of me) then 
  152.     
  153.     set newmove = (the nextmove of me)
  154.     set the nextmoveflag  of me = false
  155.     
  156.     set newmove = mcheck ( me, newmove )
  157.     
  158.     mmove gsound, #player, mmovetokey ( me, newmove )
  159.     
  160.   else 
  161.     
  162.     -- check if we should autorepeat
  163.     -- either the joystick or combat keys
  164.     -- comparing priorities of each ones' suggested move
  165.     
  166.     set keymove =  mkeytomove ( me, ( mgetlatest ( gkey ) ) )
  167.     set joymove =  mkeytomove ( me, ( mgetlatest ( gjoystick ) ) )
  168.     
  169.     set keypriority = getaprop ( priorityindex , keymove )
  170.     set joypriority = getaprop ( priorityindex , joymove ) 
  171.     
  172.     if joypriority > keypriority then  
  173.       set newmove = joymove
  174.     else
  175.       if getaprop ( repeatindex , keymove ) then set newmove = keymove
  176.       else  set newmove = mkeytomove ( me , #idle )   
  177.     end if
  178.     
  179.     set newmove = mcheck ( me, newmove )
  180.     
  181.   end if
  182.   
  183.   msetcurrentmove me, newmove
  184.   
  185.   --   put "out manimfinish: " 
  186.   
  187. end manimfinish
  188.  
  189. -- ==================================================
  190. -- mstart method
  191. -- --------------------------------------------------
  192. on mstart me
  193.   
  194.   --  put "in start player"
  195.   
  196.   set the nextmove of me = 0
  197.   set the nextmoveflag  of me = false
  198.   
  199.   set the cell of me =  - 4
  200.   
  201.   set the direction of me =  #right
  202.   msetcurrentmove me, #walkright
  203.   
  204.   mbatchadd ( gcell, the cell of me, me)
  205.   
  206.   set theloch = ( mcell2screen ( gcell, the cell of me ) )  
  207.   
  208.   set theloc = point ( theloch, mgetfloor ( gcell ) )
  209.   set offset = ( mgetstartoffset ( gcell, the direction of me , #player ) ) 
  210.   
  211.   msetloc ( me, theloc + offset )
  212.   
  213.   mwalkon walkon
  214.   
  215.   mdraw glife
  216.   mdraw gscore
  217.   
  218.   mset ghealth, ( the health of me )
  219.   mforcedraw ghealth
  220.   
  221.   --  put "out start player"
  222.   
  223. end mstart me
  224.  
  225. -- ==================================================
  226. -- mwalkonfinish method
  227. -- --------------------------------------------------
  228. on mwalkonfinish me
  229.   
  230.   --  put "in mwalkonfinish player"
  231.   
  232.   mbatchadd ( gcell, the cell of me, me)
  233.   msetcurrentmove me, #idleright
  234.   
  235.   mforcedraw ghealth
  236.   
  237.   --  put "out mwalkonfinish player"
  238.   
  239. end mwalkonfinish me
  240.  
  241. -- ==================================================
  242. -- mhurt method
  243. -- --------------------------------------------------
  244. on mhurt me , attackmove, starloc
  245.   
  246.   --  put "in mhurt"
  247.   
  248.   set flag = mcheckhurt ( me , attackmove, starloc )
  249.   
  250.   mset ghealth, ( the health of me )
  251.   
  252.   --  put "out mhurt"
  253.   
  254.   return flag
  255.   
  256. end mhurt
  257.  
  258. -- ==================================================
  259. -- mhit method
  260. -- --------------------------------------------------
  261.  
  262. on mhit me, theloc
  263.   
  264.   --  put "in mhit player"
  265.   
  266.   if  ilk ( theloc, #point ) then
  267.     
  268.     if  ( mgetcurrentkey ( me ) = #bounce )  then
  269.       mstart gstar, ( the data of me ), ( the screenloc of me + theloc )
  270.     else if mhit ( ancestor, theloc )   then
  271.       --      put "hit baddy/boss"
  272.     end if
  273.     
  274.     
  275.   else 
  276.     mdie me
  277.   end if
  278.   
  279.   --  put "out mhit player"
  280.   
  281. end mhit 
  282.  
  283. -- ==================================================
  284. -- mbaddydead method
  285. -- --------------------------------------------------
  286. on mbaddydead me
  287.   
  288.   --  put "in mbaddydead"
  289.   
  290.   set score = score + 2
  291.   mset gscore, score
  292.   
  293.   --  put "out mbaddydead"
  294.   
  295. end  mbaddydead me
  296.  
  297.  
  298. -- ==================================================
  299. -- mbossdead method
  300. -- --------------------------------------------------
  301. on mbossdead me
  302.   
  303.   --  put "in mbossdead"
  304.   
  305.   set score = score + 20
  306.   mset gscore, score
  307.   
  308.   --  put "out mbossdead"
  309.   
  310. end  mbossdead me
  311.  
  312. -- ==================================================
  313. -- mdie method
  314. -- --------------------------------------------------
  315. on mdie me
  316.   
  317.   --  put "in mdie player"
  318.   
  319.   mabort me
  320.   
  321.   set lives = lives - 1
  322.   
  323.   if lives < 0 then 
  324.     hendgame
  325.     go frame "lose"
  326.     abort
  327.   end if
  328.   
  329.   mset glife, lives
  330.   
  331.   set the health of me = fullhealth
  332.   
  333.   mset ghealth, ( the health of me )
  334.   
  335.   set newkey = #birth
  336.   set newmove = mkeytomove ( me, newkey )
  337.   msetcurrentmove ( me , newmove )
  338.   
  339.   --  put "out mdie player"
  340.   
  341. end mdie 
  342.  
  343. -- ==================================================
  344. -- mcheck method
  345. -- --------------------------------------------------
  346. on mcheck me, newmove
  347.   
  348.   --  put "in mcheck player class :"
  349.   
  350.   -- we check that the player isnt walking into another actor
  351.   -- we check that the player isnt walking offscreen
  352.   
  353.   -- we bounce back jumping offscreen players
  354.   
  355.   case newmove of
  356.     #walkleft: 
  357.       set who = mcheck ( gcell, ( the cell of me ) ,  #left )
  358.       if not ( count ( who ) = 0 ) then set newmove = #idleleft
  359.       if ( the cell of me ) < 4 then set newmove = #idleleft
  360.       
  361.     #walkright: 
  362.       set who = mcheck ( gcell, ( the cell of me ) , #right )
  363.       if not ( count ( who ) = 0 ) then set newmove = #idleright
  364.       if ( the cell of me ) > 26 then set newmove = #idleright
  365.       
  366.     #jumpleft:
  367.       if ( the cell of me ) < 10 then set newmove = #idleleft
  368.       else if ( the type of ggame = #boss ) then set newmove =  mbounce ( me , newmove )
  369.       
  370.       
  371.     #jumpright:
  372.       if ( the cell of me ) > 19 then set newmove = #idleright
  373.       else if ( the type of ggame = #boss ) then set newmove =  mbounce ( me , newmove )
  374.       
  375.   end case
  376.   
  377.   return newmove
  378.   
  379.   --  put "out mcheck player class :"
  380.   
  381. end mcheck
  382.  
  383. -- ==================================================
  384. -- mbounce method
  385. -- --------------------------------------------------
  386. on mbounce me, newmove
  387.   
  388.   --  put "in mbounce player"
  389.   
  390.   set distance =  ( the cell of gboss - the cell of me )
  391.   
  392.   case sense ( distance ) of 
  393.     1 : 
  394.       if ( the direction of me = #left ) then return newmove
  395.     -1 :
  396.       if ( the direction of me = #right ) then return newmove
  397.   end case
  398.   
  399.   if abs (distance) = 12 then 
  400.     
  401.     case ( the direction of me ) of 
  402.       #left:  set walkcell = the cell of me - 8
  403.       #right:  set walkcell = the cell of me + 11
  404.     end case
  405.     
  406.     if  count ( mget ( gcell, walkcell ) ) then
  407.       set distance = 11
  408.     end if
  409.     
  410.   end if
  411.   
  412.   set thelist = getaprop ( bounceindex , ( the direction of me ) )
  413.   set bounce = getaprop ( thelist , abs (distance) )
  414.   
  415.   -- put "bounce: " , bounce
  416.   -- put "distance: " , abs (distance) 
  417.   
  418.   if voidp ( bounce ) then return newmove
  419.   else return bounce
  420.   
  421.   -- put "out mbounce player"
  422.   
  423. end mbounce
  424.  
  425. -- ==================================================
  426. -- mcheckstun method
  427. -- --------------------------------------------------
  428. on mcheckstun me
  429.   
  430.   -- put "in mcheckstun player"
  431.   
  432.   if ( mgetcurrentkey ( me ) = #jump ) then
  433.     
  434.     set who = mbatchcheck ( gcell , ( the cell of me ), [ me ] )
  435.     
  436.     if count ( who ) then 
  437.       
  438.       repeat with baddy in who
  439.         set the health of baddy = 0
  440.         mhurt baddy , ( the currentmove of me ), 0
  441.       end repeat
  442.       
  443.       mstun me
  444.       return true
  445.       
  446.     end if
  447.     
  448.   else if ( mgetcurrentkey ( me ) = #bounce ) then
  449.     
  450.     mstun me
  451.     return true
  452.     
  453.   end if 
  454.   
  455.   -- put "out mcheckstun player"
  456.   
  457.   return false
  458.   
  459. end mcheckstun
  460.  
  461. -- ==================================================
  462. -- stun method
  463. -- --------------------------------------------------
  464. on mstun me
  465.   
  466.   set the health of me = the health of me - 50
  467.   mset ghealth, ( the health of me )
  468.   
  469.   if the health of me <= 0 then 
  470.     set nextkey = #die
  471.     mstartdie me
  472.   else set nextkey = #stun
  473.   
  474.   set newmove = mkeytomove ( me, nextkey )
  475.   
  476.   mmove gsound, #player, nextkey
  477.   
  478.   -- put "stunned!: " , newmove
  479.   
  480.   msetcurrentmove me, newmove
  481.   
  482. end mstun me
  483.  
  484. -- ==================================================
  485. -- mdodamage method
  486. -- --------------------------------------------------
  487. on mdodamage me, thedamage
  488.   
  489.   mset ghealth, the health of me
  490.   mdamage me, thedamage
  491.   
  492. end mdodamage
  493.  
  494. -- ==================================================
  495. -- mvictory method
  496. -- --------------------------------------------------
  497. on mvictory me
  498.   
  499.   --  put "in mvictory player"
  500.   
  501.   mvictory victory
  502.   
  503.   set bonus = mgetbonus ( ggame )
  504.   --  put  "player bonus: " , bonus
  505.   
  506.   if bonus then
  507.     set score = score + bonus
  508.     manimset gscore, score
  509.   end if
  510.   
  511.   --  put "out mvictory player"
  512.   
  513. end mvictory
  514.